package LeetCodeHot100TopInterview;

public class Q066_PlusOne {

    //加一
    //考进位
    public int[] plusOne(int[] digits) {

        if (digits == null || digits.length == 0){
            return new int[]{};
        }

        for (int i = digits.length - 1; i >= 0 ; i--) {
            if (digits[i] == 9){
                digits[i] = 0;
            }else {
                digits[i] = digits[i] + 1;
                break;
            }
        }
        //99999
        if (digits[0] == 0){
            int[] ans = new int[digits.length + 1];
            ans[0] = 1;
            for (int i = 1; i < ans.length; i++) {
                ans[i] = 0;
            }
            return ans;
        }

        return digits;
    }
}
